package org.adorsys.aderp.cash.work.encashment.redirect;

import java.math.BigDecimal;

import org.apache.commons.lang3.StringUtils;
import org.springframework.util.Assert;


public class CashRegisterComponentHelper {
	
	public static String transformComponentToString(CashRegItemComponent component){
		Assert.notNull(component, "The Component might not be null");
		StringBuilder stringComponent = new StringBuilder();
		stringComponent.append(mountCashRegItemKeyParam(component.getCashRegItemKey()));
		stringComponent.append("&"+mountQtyParam(component.getQty()));
		stringComponent.append("&"+mountUnitPriceParam(component.getUnitPrice()));
		stringComponent.append("&"+mountAmountParam(component.getAmount()));
		return stringComponent.toString();
	}
	
	public static CashRegItemComponent transformStringToComponent(){
		// TODO
		return null;
	}
	
	private static String mountCashRegItemKeyParam(String cashRegItemKey){
		if(StringUtils.isEmpty(cashRegItemKey)) throw new NullPointerException("The Cash Reg item  might not be null");
		return "cashRegItemKey="+cashRegItemKey;
	}
	private static String mountQtyParam(BigDecimal qty){
		if(qty == null) throw new NullPointerException("The Qty might not be null");
		return "qty="+qty;
	}
	private static String mountUnitPriceParam(BigDecimal unitPrice){
		if(unitPrice == null) throw new NullPointerException("The unit Price might not be null");
		return "unitPrice="+unitPrice;
	}
	private static String mountAmountParam(BigDecimal amount){
		if(amount == null) throw new NullPointerException("The Amount might not be null");
		return "amount="+amount;
	}
	
}
